using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Framework.Library.Components.Security;
using Framework.Library.Components.Commands;
using Framework.Library;
using Framework.Library.Utilities.Database;
using Framework.Library.Components.Database;
using Framework.Library.Utilities;

namespace Framework.Portal.Administrator.Database
{
    public partial class ViewsAction : AuthenticatedControl
    {
        _View objView = new _View();
        protected void Page_Load(object sender, EventArgs e)
        {
            if ((!CurrentUser.IsSuperAdmin && CommandController.IsSystemModule(AppEnv.CommandID())) || !CommandController.IsAvailableForUser(AppEnv.CommandID(), CurrentUser.UserID, Convert.ToInt32(AppEnv.PortalId())))
                Response.Redirect(AppEnv.ADMIN_CMD, true);
            if (!IsPostBack)
            {
                //switch on action
                switch (Request.QueryString["action"].ToString())
                {
                    case "drop":
                        loadDropForm();
                        break;
                }
                lblCommandName.Text = AppEnv.CommandName();
                lnkViewList.NavigateUrl = AppEnv.AdminUrlParams(CommandController.GetCommandbyID((int)PortalControls.View));
                lnkViewDetails.NavigateUrl = AppEnv.AdminUrlParams(CommandController.GetCommandbyID((int)PortalControls.ViewProperty)) + "&id=" + Request.QueryString["id"].ToString();
            }
        }

        #region "Drop"

        private void loadDropForm()
        {   
            //Load Default properties
            objView.ID = Convert.ToInt64(Request["id"]);
            objView.LoadProperties();
            lblDropViewName.Text = objView.Owner + "." + objView.Name;
        }

        protected void btnDrop_Click(object sender, EventArgs e)
        {
            try
            {
                //Load view properties
                objView.ID = Convert.ToInt64(Request["id"]);
                objView.LoadProperties();
                //Drop view
                objView.Drop();
                Response.Redirect(AppEnv.AdminUrlParams(CommandController.GetCommandbyID((int)PortalControls.View)));
            }
            catch (Exception ex)
            {
                lblError.Visible = true;
                lblError.Text = "<p>" + ex.Message + "</p>";
            }
        }

        #endregion
    }
}